package com.sixkey.controller.app;


import com.sixkey.entity.vo.MessageVo;
import com.sixkey.response.Response;
import com.sixkey.service.IMessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-10-27
 */
@Slf4j
@Validated
@CrossOrigin
@RestController
@RequestMapping("/api/message")
@RequiredArgsConstructor
public class ApiMessageController {

    private final IMessageService messageService;

    /**
     * 管理员或者主管发送消息保存
     * @param
     * @return
     */
    @PostMapping("/save")
    public Response saveMessage(@RequestBody MessageVo messageVo) {
        messageService.saveMessage(messageVo);
        return Response.success();
    }

    /**
     * 获取刚发的消息
     * @param
     * @return
     */
    @GetMapping("/getMessage/{id}")
    public Response getMessage(@PathVariable("id") int id) {
        Map<String,Object> map = messageService.getMessage(id);
        return Response.success(map);
    }

    /**
     * 获取管理员或者主管发布的历史通知
     * @param id
     * @return
     */
    @GetMapping("/history/{id}")
    public Response getHistoryMessage(@PathVariable("id") int id) {
        List<Map<String,Object>> mapList = messageService.getHistoryMessage(id);
        return Response.success(mapList);
    }

    /**
     * 获取管理员或者主管发布的新通知
     * @param id
     * @return
     */
    @GetMapping("/new/{id}")
    public Response getNewMessage(@PathVariable("id") int id) {
        List<Map<String,Object>> mapList = messageService.getNewMessage(id);
        return Response.success(mapList);
    }

    /**
     * 获获取自己发布过的通知历史
     * @param id
     * @return
     */
    @GetMapping("/history/oneself/{id}")
    public Response getHistoryMessageByOneself(@PathVariable("id") int id) {
        List<Map<String,Object>> mapList = messageService.getHistoryMessageByOneself(id);
        return Response.success(mapList);
    }

    /**
     * 获取当前登录用户是否有需要知道的通知
     * @param id
     * @return
     */
    @GetMapping("/badge/{id}")
    public Response getBadge(@PathVariable("id") int id) {
        log.info("获取当前登录用户是否有需要知道的通知请求进来了--------");
        int badge = messageService.getBadge(id);
        return Response.success(badge);
    }
}
